<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.5.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":true,"scrollpercent":true},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="Maven 是一个 Java 项目的自动化构建工具">
<meta name="keywords" content="Maven">
<meta property="og:type" content="article">
<meta property="og:title" content="Maven">
<meta property="og:url" content="http:&#x2F;&#x2F;beiran.top&#x2F;Maven&#x2F;Maven&#x2F;index.html">
<meta property="og:site_name" content="北然">
<meta property="og:description" content="Maven 是一个 Java 项目的自动化构建工具">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http:&#x2F;&#x2F;beiran.top&#x2F;Maven&#x2F;Maven&#x2F;image-20200115025641639.png">
<meta property="og:image" content="http:&#x2F;&#x2F;beiran.top&#x2F;Maven&#x2F;Maven&#x2F;image-20200115022433670.png">
<meta property="og:updated_time" content="2020-02-08T08:21:17.143Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http:&#x2F;&#x2F;beiran.top&#x2F;Maven&#x2F;Maven&#x2F;image-20200115025641639.png">

<link rel="canonical" href="http://beiran.top/Maven/Maven/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>Maven | 北然</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">北然</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">insomniac</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/schedule/" rel="section"><i class="fa fa-fw fa-calendar"></i>日程表</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://beiran.top/Maven/Maven/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.jpg">
      <meta itemprop="name" content="beiranc">
      <meta itemprop="description" content="你在想peach">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="北然">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Maven
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-01-11 17:35:09" itemprop="dateCreated datePublished" datetime="2020-01-11T17:35:09+08:00">2020-01-11</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Maven/" itemprop="url" rel="index">
                    <span itemprop="name">Maven</span>
                  </a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h5 id="Maven-是一个-Java-项目的自动化构建工具"><a href="#Maven-是一个-Java-项目的自动化构建工具" class="headerlink" title="Maven 是一个 Java 项目的自动化构建工具"></a><a href="https://maven.apache.org/" target="_blank" rel="noopener">Maven</a> 是一个 Java 项目的自动化构建工具<a id="more"></a></h5><hr>
<h5 id="构建过程"><a href="#构建过程" class="headerlink" title="构建过程"></a>构建过程</h5><ul>
<li>清理：将之前编译得到的旧的 class 字节码删除，为下一次编译做准备</li>
<li>编译：将 Java 源码编译成 class 字节码</li>
<li>测试：自动调用 Junit 执行测试</li>
<li>报告：测试的结果</li>
<li>打包：Web 工程生成 war 包，Java 工程生成 jar 包</li>
<li>安装：将打包生成的文件复制到仓库中的指定位置</li>
<li>部署：将 Web 工程生成的 war 包复制到 Web 容器的指定目录中</li>
</ul>
<hr>
<h5 id="安装-Maven（见官网-Maven-Install）"><a href="#安装-Maven（见官网-Maven-Install）" class="headerlink" title="安装 Maven（见官网 Maven Install）"></a>安装 Maven（见官网 <a href="https://maven.apache.org/install.html" target="_blank" rel="noopener">Maven Install</a>）</h5><hr>
<h5 id="Maven-的核心概念"><a href="#Maven-的核心概念" class="headerlink" title="Maven 的核心概念"></a>Maven 的核心概念</h5><ul>
<li><p><a href="https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html" target="_blank" rel="noopener">约定的目录结构</a></p>
</li>
<li><p><a href="https://maven.apache.org/guides/introduction/introduction-to-the-pom.html" target="_blank" rel="noopener">POM</a></p>
</li>
<li><p>坐标</p>
<ul>
<li>使用下面三个向量在仓库中唯一定位一个 Maven 工程<ul>
<li>groupid : 公司或组织域名倒序 + 项目名</li>
<li>artifactid : 模块名</li>
<li>version : 版本</li>
</ul>
</li>
</ul>
</li>
<li><p><a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html" target="_blank" rel="noopener">依赖</a></p>
<ul>
<li><p>Maven 解析依赖信息时会到本地仓库中查找被依赖的 jar 包。对于自己开发的 Maven 工程，使用 <code>mvn install</code> 命令安装后才能被别的工程引用（这一步的目的是在本地仓库中生成相应文件）</p>
</li>
<li><p>依赖的范围</p>
<ul>
<li><p>dependency 标签中的 scope 标签设置的就是依赖的范围</p>
</li>
<li><p>可选值如下：</p>
<ul>
<li>compile（默认）<ul>
<li>对主程序是否有效：有效</li>
<li>对测试程序是否有效：有效</li>
<li>是否参与打包：参与</li>
<li>是否参与部署：参与</li>
</ul>
</li>
<li>provided<ul>
<li>对主程序是否有效：有效</li>
<li>对测试程序是否有效：有效</li>
<li>是否参与打包：不参与</li>
<li>是否参与部署：不参与</li>
</ul>
</li>
<li>test<ul>
<li>对主程序是否有效：无效</li>
<li>对测试程序是否有效：有效</li>
<li>是否参与打包：不参与</li>
<li>是否参与部署：不参与</li>
</ul>
</li>
<li>system</li>
<li>import</li>
<li>runtime</li>
</ul>
<p><img src="image-20200115025641639.png" alt="image-20200115025641639"></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>仓库</p>
<ul>
<li><p>本地仓库</p>
</li>
<li><p>远程仓库</p>
<ul>
<li>私服：架设在当前局域网环境下，为当前局域网范围内的所有 Maven 工程服务</li>
<li>中央仓库：架设在 Internet 上，为全世界所有 Maven 工程服务</li>
<li>中央仓库的镜像：架设在各大洲，为中央仓库分担流量，减轻中央仓库压力，同时更快的响应用户请求</li>
</ul>
<p><img src="image-20200115022433670.png" alt="image-20200115022433670"></p>
</li>
</ul>
</li>
<li><p>生命周期/插件/目标</p>
<ul>
<li>Maven 生命周期定义了各个构建环节的执行顺序，有了这个顺序清单，Maven 才可以自动化的执行构建命令</li>
<li>Maven 有三套相互独立的生命周期，分别是：<ul>
<li>Clean Lifecycle : 在进行真正的构建之前进行一些清理工作<ul>
<li>Clean Lifecycle 一共包含三个阶段：<ul>
<li>pre-clean : 执行一些需要在 clean 之前完成的工作</li>
<li>clean : 移除所有上一次构建生成的文件</li>
<li>post-clean : 执行一些需要在 clean 之后立即完成的工作</li>
</ul>
</li>
</ul>
</li>
<li>Default Lifecycle : 构建的核心部分，编译、测试、打包、安装、部署等<ul>
<li>Default Lifecycle 中比较重要的阶段：<ul>
<li>validate</li>
<li>generate-sources</li>
<li>process-sources</li>
<li>generate-resources</li>
<li>process-resources : 复制并处理资源文件至目标目录，准备打包</li>
<li>compile : 编译项目的源码</li>
<li>process-classes</li>
<li>generate-test-sources</li>
<li>process-test-sources</li>
<li>generate-test-resources</li>
<li>process-test-resources : 复制并处理资源文件至目标测试目录</li>
<li>test-compile : 编译测试源码</li>
<li>process-test-classes</li>
<li>test : 使用单元测试框架运行测试，这些测试代码不会被打包或者部署</li>
<li>prepare-package</li>
<li>package : 接受编译好的代码并打包成可发布的格式。如 JAR、WAR 等</li>
<li>pre-integration-test</li>
<li>integration-test</li>
<li>post-integration-test</li>
<li>verify</li>
<li>install : 将包安装到本地仓库</li>
<li>deploy : 将最终的包复制到远程仓库</li>
</ul>
</li>
</ul>
</li>
<li>Site Lifecycle : 生成项目报告，站点，发布站点<ul>
<li>Site Lifecycle 一共包含四个阶段：<ul>
<li>pre-site : 执行一些需要在生成站点文档之前完成的工作</li>
<li>site(常用) : 生成项目的站点文档</li>
<li>post-site : 执行一些需要在生成站点文档之后完成的工作，并且为部署做准备</li>
<li>site-deploy(常用) : 将生成的站点文档部署到特定的服务器上</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><strong>Maven 在运行任何一个阶段的时候，它前面的所有阶段都会被执行</strong>，这是 Maven 能够自动执行构建过程的重要原因</li>
<li>生命周期的各个阶段仅仅定义了要执行的任务是什么，各个阶段和插件的目标是对应的，相似的目标由特定的插件来完成</li>
</ul>
</li>
<li><p>继承</p>
<ul>
<li><p>原因：由于 test 范围不能传递，所以必然会分散在各个模块中，很容易造成版本不一致</p>
</li>
<li><p>解决方案：将相同的依赖（不能传递的）版本统一提取到 parent 中，在 子工程声明该依赖时不指定版本，以 parent 的为准。注意：配置继承之后需要先 install parent </p>
</li>
<li><p>配置方式：</p>
<ul>
<li><p>创建一个 Maven 工程作为 parent，注意：打包的方式为 pom</p>
</li>
<li><p>在子工程中声明对 parent 的引用</p>
  <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">parent</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span><span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span><span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span><span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">&lt;!-- 以当前工程的 pom.xml 文件为基准的 parent 中 pom.xml 文件的相对路径 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">relativePath</span>&gt;</span><span class="tag">&lt;/<span class="name">relativePath</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">parent</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>将子工程的坐标中与 parent 坐标中重复的内容删除</p>
</li>
<li><p>在 parent 中统一管理不能传递的依赖</p>
  <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependencyManagement</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    	<span class="tag">&lt;<span class="name">denpendency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span><span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span><span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span><span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span><span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">denpendency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencyManagement</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在子工程中删除不能传递的依赖的版本号部分</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>聚合</p>
<ul>
<li><p>作用：一键安装各个模块</p>
</li>
<li><p>配置方式：</p>
<ul>
<li><p>指定一个总的工程，在这个工程中配置各个参与聚合的模块</p>
  <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">modules</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 指定各个子工程的相对路径 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">module</span>&gt;</span><span class="tag">&lt;/<span class="name">module</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">modules</span>&gt;</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
</li>
</ul>
</li>
</ul>
<hr>
<h5 id="常用-Maven-命令"><a href="#常用-Maven-命令" class="headerlink" title="常用 Maven 命令"></a>常用 Maven 命令</h5><ul>
<li>注：执行与构建过程相关的命令时，必须进入 pom.xml 所在目录</li>
<li><code>mvn clean</code> : 清理</li>
<li><code>mvn compile</code> : 编译主程序</li>
<li><code>mvn test-compile</code> : 编译测试程序</li>
<li><code>mvn test</code> : 执行测试</li>
<li><code>mvn package</code> : 打包</li>
<li><code>mvn install</code> : 安装</li>
<li><code>mvn site</code> : 生成站点</li>
</ul>
<hr>
<h5 id="本地仓库默认位置"><a href="#本地仓库默认位置" class="headerlink" title="本地仓库默认位置"></a>本地仓库默认位置</h5><ul>
<li><code>${user.home}/.m2/repository</code> （例如 Windows 下为 C:\Users\用户名\.m2\repository）。如需修改本地仓库位置，则需要到 Maven 安装目录下的 conf\settings.xml 文件中找到 localRepository 标签内容即可</li>
</ul>
<hr>
<h5 id="Eclipse-设置"><a href="#Eclipse-设置" class="headerlink" title="Eclipse 设置"></a>Eclipse 设置</h5><ul>
<li>Installations : 更改为自己安装的 Maven 目录（不建议使用 Eclipse 自带的）</li>
<li>User Settings : 更改本地仓库的位置</li>
</ul>
<hr>
<h5 id="依赖的传递性"><a href="#依赖的传递性" class="headerlink" title="依赖的传递性"></a>依赖的传递性</h5><ul>
<li>可以传递的依赖不必在每个模块工程中都重复声明，在底层工程中依赖一次即可</li>
<li>在 compile/test/provided 三个范围中只有 compile 范围可以传递</li>
</ul>
<hr>
<h5 id="依赖的排除"><a href="#依赖的排除" class="headerlink" title="依赖的排除"></a>依赖的排除</h5><ul>
<li>需要设置依赖排除的场合：排除掉不希望加入工程中的 jar 包</li>
<li>设置方式：某个 dependency 标签中加入 exclusions 标签，在 exclusions 标签中填入需要排除的依赖的 groupId 以及 artifactId 即可</li>
</ul>
<hr>
<h5 id="依赖的原则"><a href="#依赖的原则" class="headerlink" title="依赖的原则"></a>依赖的原则</h5><ul>
<li>作用：解决模块工程之间的 jar 包冲突问题</li>
<li>路径最短优先原则</li>
<li>路径长度相同时先声明者优先（先声明指的是路径相同的两个 dependency 标签的声明顺序）</li>
</ul>
<hr>
<h5 id="统一管理依赖的版本"><a href="#统一管理依赖的版本" class="headerlink" title="统一管理依赖的版本"></a>统一管理依赖的版本</h5><ul>
<li><p>配置方式：</p>
<ul>
<li><p>使用 properties 标签，在 properties 标签内自定义一个标签统一声明版本号（ properties 标签不限于统一版本号的使用 ）</p>
  <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">defined.version</span>&gt;</span>1.2<span class="tag">&lt;/<span class="name">defined.version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在需要统一版本的位置，使用 <code>${自定义标签}</code> 来引用声明的版本号</p>
  <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;defined.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
</li>
</ul>
<hr>
<h5 id="自动部署"><a href="#自动部署" class="headerlink" title="自动部署"></a>自动部署</h5><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- pom.xml 文件中 --&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!-- 配置构建过程中的特殊设置 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 工程最终名字 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">finalName</span>&gt;</span>Test<span class="tag">&lt;/<span class="name">finalName</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 配置构建过程中需要使用的插件 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">    	<span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">        	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.codehaus.cargo<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>cargo-maven2-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.2.3<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!-- 针对插件进行的配置 --&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">                <span class="comment">&lt;!-- 配置容器的位置 --&gt;</span></span><br><span class="line">            	<span class="tag">&lt;<span class="name">container</span>&gt;</span></span><br><span class="line">                	<span class="tag">&lt;<span class="name">containerId</span>&gt;</span>tomcat9x<span class="tag">&lt;/<span class="name">containerId</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">home</span>&gt;</span>/usr/share/tomcat9<span class="tag">&lt;/<span class="name">home</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">container</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">                	<span class="tag">&lt;<span class="name">type</span>&gt;</span>existing<span class="tag">&lt;/<span class="name">type</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">home</span>&gt;</span>/usr/share/tomcat9<span class="tag">&lt;/<span class="name">home</span>&gt;</span></span><br><span class="line">                    <span class="comment">&lt;!-- 若 Tomcat 端口为默认值则不需要指定端口 --&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">                    	<span class="tag">&lt;<span class="name">cargo.servlet.port</span>&gt;</span>8080<span class="tag">&lt;/<span class="name">cargo.servlet.port</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!-- 配置插件在什么情况下执行 --&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">executions</span>&gt;</span></span><br><span class="line">            	<span class="tag">&lt;<span class="name">execution</span>&gt;</span></span><br><span class="line">                	<span class="tag">&lt;<span class="name">id</span>&gt;</span>cargo-run<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">                    <span class="comment">&lt;!-- 生命周期的阶段 --&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">phase</span>&gt;</span>install<span class="tag">&lt;/<span class="name">phase</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">goals</span>&gt;</span></span><br><span class="line">                        <span class="comment">&lt;!-- 插件的目标 --&gt;</span></span><br><span class="line">                    	<span class="tag">&lt;<span class="name">goal</span>&gt;</span>run<span class="tag">&lt;/<span class="name">goal</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;/<span class="name">goals</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">execution</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">executions</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br></pre></td></tr></table></figure>
    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Maven/" rel="tag"># Maven</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
                <a href="/Hibernate/Hibernate/" rel="next" title="Hibernate">
                  <i class="fa fa-chevron-left"></i> Hibernate
                </a>
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
                <a href="/Spring/Spring/" rel="prev" title="Spring">
                  Spring <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-5"><a class="nav-link" href="#Maven-是一个-Java-项目的自动化构建工具"><span class="nav-number">1.</span> <span class="nav-text">Maven 是一个 Java 项目的自动化构建工具</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#构建过程"><span class="nav-number">2.</span> <span class="nav-text">构建过程</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#安装-Maven（见官网-Maven-Install）"><span class="nav-number">3.</span> <span class="nav-text">安装 Maven（见官网 Maven Install）</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Maven-的核心概念"><span class="nav-number">4.</span> <span class="nav-text">Maven 的核心概念</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#常用-Maven-命令"><span class="nav-number">5.</span> <span class="nav-text">常用 Maven 命令</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#本地仓库默认位置"><span class="nav-number">6.</span> <span class="nav-text">本地仓库默认位置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Eclipse-设置"><span class="nav-number">7.</span> <span class="nav-text">Eclipse 设置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#依赖的传递性"><span class="nav-number">8.</span> <span class="nav-text">依赖的传递性</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#依赖的排除"><span class="nav-number">9.</span> <span class="nav-text">依赖的排除</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#依赖的原则"><span class="nav-number">10.</span> <span class="nav-text">依赖的原则</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#统一管理依赖的版本"><span class="nav-number">11.</span> <span class="nav-text">统一管理依赖的版本</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#自动部署"><span class="nav-number">12.</span> <span class="nav-text">自动部署</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <img class="site-author-image" itemprop="image" alt="beiranc"
    src="/images/head.jpg">
  <p class="site-author-name" itemprop="name">beiranc</p>
  <div class="site-description" itemprop="description">你在想peach</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">11</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/beiranc" title="GitHub &amp;rarr; https:&#x2F;&#x2F;github.com&#x2F;beiranc" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="/mailto:beiranlp@gmail.com" title="E-Mail &amp;rarr; mailto:beiranlp@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://plus.google.com/lintsky" title="Google &amp;rarr; https:&#x2F;&#x2F;plus.google.com&#x2F;lintsky" rel="noopener" target="_blank"><i class="fa fa-fw fa-google"></i></a>
      </span>
  </div>



      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">beiranc<br>Hosted By <a href="https://pages.github.com" target="_blank">GitHub Pages</a></span>
</div>

        












        
      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-nest@1/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/pisces.js"></script>
<script src="/js/next-boot.js"></script>



  
















  

  

</body>
</html>
